//
//  MatchViewController.m
//  FootballSport
//
//  Created by lanou3g on 15/5/28.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "MatchViewController.h"



#import "MatchAddChildVC.h"

@interface MatchViewController ()<UIScrollViewDelegate>

@end

@implementation MatchViewController

-(instancetype)init{
    if (self = [super init]) {
       
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(execute:) name:segmentSendNotification object:nil];
    }
    return self;
}

-(void)setupSubView{
    _matchScrollV = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds),CGRectGetHeight(self.view.bounds)-64-44)];
 
    _matchScrollV.contentSize = CGSizeMake(4*CGRectGetWidth(self.view.bounds),0);

    _matchView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth([UIScreen mainScreen].bounds), CGRectGetHeight([UIScreen mainScreen].bounds)-64-44)];
    _matchView.backgroundColor = [UIColor purpleColor];
    _matchScrollV.pagingEnabled = YES;
    self.matchScrollV.delegate = self;
    self.matchScrollV.pagingEnabled = YES;
    self.matchScrollV.contentOffset = CGPointMake(0, 0);
    [self.view addSubview:self.matchScrollV];
    _matchScrollV.bounces =NO;
    
    self.matchScrollV.delegate = self;
    self.matchScrollV.pagingEnabled = YES;
    self.matchScrollV.contentOffset = CGPointMake(0, 0);
    [self.view addSubview:self.matchScrollV];
    
    [MatchAddChildVC getChildWithMatchVC:self];

    



}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupSubView];
    

      
    // Do any additional setup after loading the view.
}
- (void)execute:(NSNotification*)notification{
    NSNumber *number = notification.object;
    self.matchScrollV.contentOffset = CGPointMake(CGRectGetWidth(self.view.bounds)*[number integerValue], 0);
   

}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    NSNumber *number = [NSNumber numberWithInteger:(NSInteger)(self.matchScrollV.contentOffset.x/CGRectGetWidth(self.matchScrollV.frame))];
    [[NSNotificationCenter defaultCenter] postNotificationName:scrollSendNotification object:number];
    [[NSNotificationCenter defaultCenter] postNotificationName:segmentSendNotification object:number];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
